// lang ver: 6+
// [es6入门](https://es6.ruanyifeng.com/)
// [Js教程](https://www.w3school.com.cn/js/index.asp)

function mute(...ps) {
}

function vari() {
    console.log("变量常量");
    let a = 0;
    let b = 'a';
    let c = 1.0;

    let [d, e] = [1, 2];
    let { foo, bar } = { foo: 'aaa', bar: 'bbb' };

    mute(a, b, c, d, e, foo, bar);
}

function stri() {
    console.log("字符串");
    let str = "abc";
    let lines = `
      a${str.length}
      b${1 + 2}
    `;

    for (let c of 'foo') {
        mute(c)
    }
}

function coll() {
    console.log("数组集合");
    let arr = [];
    let arr2 = [];
    let set = new Set([1, 2, 3]);
    let map = {};

    arr.push(1);
    arr2['a'] = 1;
    map['a'] = 1;
    map.a=1;

    for (let i = 0; i < arr.length; i++) {
        mute(i, arr[i]);
    }
    for (var key in arr2) {
        mute(key, arr2[key]);
    }

    console.assert(arr.length == 1);
    console.assert(arr[0] == 1);
    console.assert(arr2['a'] == 1);
    console.assert(map['a'] == 1);
}

function proc() {
    console.log("流程控制");
    if (true) {
    } else if (true) {
    } else {
    }
    for (let i = 0; i < 10; i++) {
        mute(i);
    }
    let x = 0;
    switch (x) {
        case 0:
            break;
        case 0:
            break;
        default:
    }
}
function func() {
    console.log("函数方法");

    function f(a = 1, b = 2) {
        return a + b;
    }
    f2 = (a, b) => {
        return a + b;
    }

    console.assert(f() == 3);
    console.assert(f2(1, 2) == 3);
}

function clas() {
    console.log("类和对象");
    class A {
        constructor() {
            this.a = 'a';
        }
        f(f) {
            return "f_" + this.a + f;
        }
    }
    class B extends A {
        constructor() {
            super(); //must
            this.a = 'b';
        }
        f(f) {
            return "g_" + this.a + f;
        }
    }

    let a = new A();
    let b = new B();

    console.assert(a.f('b') == 'f_ab');
    console.assert(b.f('b') == 'g_bb');
}

function test() {
    console.log("测试");
    let dt=new Date();
    let s = dt.toString("y-m-d");
    console.log(s);
}

function main() {
    console.log("Hello World");
    vari();
    stri();
    coll();
    proc();
    func();
    clas();
    test();
}

main();
